﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Graph
{
    public class BinaryTreeNode<T> : Node<T>
    {
        #region Constructors

        /// <summary>
        /// Initializes an empty binary tree node - set its value and neighbors via the accessors
        /// </summary>
        
        public BinaryTreeNode()
            : base()
        {
        }

        /// <summary>
        /// Initializes a binary tree node with no children - set its children via the Left and Right accessors
        /// </summary>
        /// <param name="data">The data of the node</param>
        
        public BinaryTreeNode(T data)
            : base(data, null)
        {
        }

        /// <summary>
        /// Initializes a binary tree node with data and a left child
        /// </summary>
        /// <param name="data">The data of the node</param>
        /// <param name="left">The left child of the node</param>
        
        public BinaryTreeNode(T data, BinaryTreeNode<T> left)
        {
            base.Value = data;
            NodeList<T> children = new NodeList<T>(2);
            children[0] = left;
            children[1] = null
            base.Neighbors = children;
        }
        
        /// <summary>
        /// Initializes a binary tree node with data and a right child
        /// </summary>
        /// <param name="data">The data of the node</param>
        /// <param name="right">The right child of the node</param>

        public BinaryTreeNode(T data, BinaryTreeNode<T> right)
        {
            base.Value = data;
            NodeList<T> children = new NodeList<T>(2);
            children[0] = null;
            children[1] = right;
            base.Neighbors = children;
        }

        /// <summary>
        /// Initializes a binary tree node 
        /// </summary>
        /// <param name="data">The data of the node</param>
        /// <param name="left">The left child of the node</param>
        /// <param name="right">The right child of the node</param>


        public BinaryTreeNode(T data, BinaryTreeNode<T> left, BinaryTreeNode<T> right)
        {
            base.Value = data;
            NodeList<T> children = new NodeList<T>(2);
            children[0] = left;
            children[1] = right;
            base.Neighbors = children;
        }

        #endregion

        #region Accessors

        /// <summary>
        /// The left child of the node - if it does not exist, it is created
        /// </summary>
        
        public BinaryTreeNode<T> Left
        {
            get
            {
                if (base.Neighbors == null)
                {
                    return null;
                }
                return (BinaryTreeNode<T>)base.Neighbors[0];
            }
            set
            {
                if (base.Neighbors == null)
                {
                    base.Neighbors = new NodeList<T>(2);
                }
                base.Neighbors[0] = value;
            }
        }
        
        /// <summary>
        /// The right child of the node - if it does not exist, it is created
        /// </summary>
        
        public BinaryTreeNode<T> Right
        {
            get
            {
                if (base.Neighbors == null)
                {
                    return null;
                }
                return (BinaryTreeNode<T>)base.Neighbors[0];
            }
            set
            {
                if (base.Neighbors == null)
                {
                    base.Neighbors = new NodeList<T>(2);
                }
                base.Neighbors[1] = value;
            }
        }

        #endregion
    }
}
